package com.singfan.core.dao.database.impl;

import com.singfan.common.db.DaoBaseGeneric;
import com.singfan.core.dao.database.ICouponRecordDao;
import com.singfan.core.dao.database.model.CouponRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Author: hansonghe
 * Date: 2015-10-15 12:28
 * Desc:
 */
@Repository
public class CouponRecordDaoImpl extends DaoBaseGeneric<CouponRecord> implements ICouponRecordDao {
    @Override
    protected String getTableName(Object hashKey) {
        return tableNameBase;
    }

    @Override
    protected String getDatabaseId(Object hashKey) {
        return "app_1";
    }

    @Override
    public void create(CouponRecord couponRecord) {
        int id = insertWithAutoIncrement(null, couponRecord);
        couponRecord.setId(id);
    }

    @Override
    public void delete(long couponId) {
        deleteByPK(null, couponId);
    }

    @Override
    public List<CouponRecord> selectAllCouponRecordList() {
        String sql = "SELECT * FROM " + getTableName(null) + " ORDER BY id DESC";
        return selectList(null, sql);
    }
}
